package top.api.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;



/**
 * 通用类
 * @Author yql
 * @Date 2023-04-13 10:24
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResUlt<T>{
    private int code;
    private String msg;
    private T data;

    public static ResUlt<Object> success(){
        ResUlt<Object> resUlt = new ResUlt<>();
        resUlt.setCode(200);
        resUlt.setMsg("success");
        return resUlt;
    }
    public static ResUlt<Object> success(String msg){
        ResUlt<Object> resUlt = new ResUlt<>();
        resUlt.setCode(200);
        resUlt.setMsg(msg);
        return resUlt;
    }

    public static <T> ResUlt<T> success(String msg, T data){
        ResUlt<T> resUlt = new ResUlt<>();
        resUlt.setCode(200);
        resUlt.setMsg(msg);
        resUlt.setData(data);
        return resUlt;
    }

    public static <T> ResUlt<T> success(T data){
        ResUlt<T> resUlt = new ResUlt<>();
        resUlt.setCode(200);
        resUlt.setMsg("success");
        resUlt.setData(data);
        return resUlt;
    }

    public static <T> ResUlt<T> success(String msg, Integer code ,T data){
        ResUlt<T> resUlt = new ResUlt<>();
        resUlt.setCode(code);
        resUlt.setMsg(msg);
        resUlt.setData(data);
        return resUlt;
    }
    public static ResUlt<Object> error(){
        ResUlt<Object> resUlt = new ResUlt<>();
        resUlt.setCode(500);
        resUlt.setMsg("error");
        return resUlt;
    }
    public static ResUlt<Object> error(String msg){
        ResUlt<Object> resUlt = new ResUlt<>();
        resUlt.setCode(500);
        resUlt.setMsg(msg);
        return resUlt;
    }

    public static <T> ResUlt<T> error(String msg, T data){
        ResUlt<T> resUlt = new ResUlt<>();
        resUlt.setCode(500);
        resUlt.setMsg(msg);
        resUlt.setData(data);
        return resUlt;
    }



    public static <T> ResUlt<T> error(String msg, Integer code ,T data){
        ResUlt<T> resUlt = new ResUlt<>();
        resUlt.setCode(code);
        resUlt.setMsg(msg);
        resUlt.setData(data);
        return resUlt;
    }

    public static <T> ResUlt<T> error(T data){
        ResUlt<T> resUlt = new ResUlt<>();
        resUlt.setCode(500);
        resUlt.setMsg("error");
        resUlt.setData(data);
        return resUlt;
    }

    public static ResUlt<Object> successOrError(int count){
        if (count  > 0){
            return success();
        }else {
            return error();
        }
    }

    public static ResUlt<Object> successOrError(boolean flag){
        if (flag){
            return success();
        }else {
            return error();
        }
    }
}
